cmake_minimum_required(VERSION 3.10)

# 判断是否为MSVC编译器
if (MSVC)
    set(CMAKE_CXX_STANDARD 23)
    add_compile_options(/EHsc)

    # 判断是否为64位系统
    if (CMAKE_SIZEOF_VOID_P EQUAL 8)
        set(COMPILER_ARCH "WIN64")
        set(COMPILER_ARCH_WIN64 1)
    else()
        set(COMPILER_ARCH "WIN32")
        set(COMPILER_ARCH_WIN32 1)
    endif()
    set(COMPILER_SYSTEM "WINDOWS")
    set(COMPILER_SYSTEM_WINDOWS 1)
# 判断是否为MinGW编译器
elseif (MINGW)
    set(CMAKE_CXX_STANDARD 20)
    set(COMPILER_ARCH "MINGW")
    set(COMPILER_ARCH_MINGW 1)
    set(COMPILER_SYSTEM "WINDOWS")
    set(COMPILER_SYSTEM_WINDOWS 1)
    add_definitions("-Wall -O3 -g")
else()
    # 判断架构
    string(FIND "${CMAKE_CXX_COMPILER}" "aarch64" compiler_aarch64_pos)
    string(FIND "${CMAKE_CXX_COMPILER}" "arm" compiler_arm_pos)
    
    if(compiler_aarch64_pos GREATER -1)
        set(CMAKE_CXX_STANDARD 14)
        set(COMPILER_ARCH "AARCH64")
        set(COMPILER_ARCH_AARCH64 1)
    elseif(compiler_arm_pos GREATER -1)
        set(CMAKE_CXX_STANDARD 11)
        set(COMPILER_ARCH "ARM32")
        set(COMPILER_ARCH_ARM32 1)
    elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "amd64")
        set(CMAKE_CXX_STANDARD 20)
        set(COMPILER_ARCH "X86_64")
        set(COMPILER_ARCH_X86_64 1)
    elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86" OR CMAKE_SYSTEM_PROCESSOR MATCHES "i686" OR CMAKE_SYSTEM_PROCESSOR MATCHES "i386")
        set(CMAKE_CXX_STANDARD 20)
        set(COMPILER_ARCH "X86")
        set(COMPILER_ARCH_X86 1)
    else()
        message(FATAL_ERROR "Unknown processor: ${CMAKE_SYSTEM_PROCESSOR}")
    endif() 
    set(COMPILER_SYSTEM_LINUX 1)
    add_definitions("-Wall -O3 -g")
    set(COMPILER_SYSTEM "LINUX")
endif()
message(STATUS "Compiler: ${COMPILER_SYSTEM} ${COMPILER_ARCH}")

